

#ifndef __COMM_MSG_SENSOR_FAULT_STATE_H__
#define __COMM_MSG_SENSOR_FAULT_STATE_H__

#include "comm/comm_topic_name.h"
#include "comm/comm_base.h"
#include <comm_msg/sensorFaultState.h>

#include <ros/ros.h>

#include <iostream>
#include <list>
#include <vector>

using namespace std;

/**************************************************************************************
功能描述: 传感器故障状态
修改记录:
**************************************************************************************/
typedef struct {
    BOOL isLidarFault;
    BOOL isVisionFault;
    BOOL isRadarFault;

    void SetZero(void)
    {
        isLidarFault  = false;
        isVisionFault = false;
        isRadarFault = false;
    }
    
} SENSOR_FAULT_STATE_STRU;

/**************************************************************************************
功能描述: 传感器故障状态消息接收器
修改记录:
**************************************************************************************/
class SENSOR_FAULT_STATE_RECEIVER_C
{
public:
    SENSOR_FAULT_STATE_RECEIVER_C(ros::NodeHandle &nh, double overTime = 0.2)
    {
        subscriber_ = nh.subscribe(TOPIC_NAME_SENSOR_FAULT_STATE, 1, &SENSOR_FAULT_STATE_RECEIVER_C::ReceiveMsgCallBack, this);
        objInvalidTimer_.SetOverTime(overTime);
    }

    INT32 Get(SENSOR_FAULT_STATE_STRU &stState)
    {
        if (objInvalidTimer_.IsTimeOut()) {
            return -1;
        }

        stState = stState_;
        return 0;
    }
    
private:
    ros::Subscriber         subscriber_;
    TIMER_C                 objInvalidTimer_;       /* 数据失效定时器，超时后数据无效 */
    SENSOR_FAULT_STATE_STRU stState_;

    void ReceiveMsgCallBack(const comm_msg::sensorFaultState::ConstPtr &pstMsg)
    {
        R_ASSERT(pstMsg != NULL, NOTHING);

        objInvalidTimer_.Reset();

        stState_.isLidarFault  = BOOL(pstMsg->isLidarFault);
        stState_.isVisionFault = BOOL(pstMsg->isVisionFault);
        stState_.isRadarFault = BOOL(pstMsg->isRadarFault);
    }
};


#endif

